/* 
 * Copyright (c) 2022, CENTRIN.CIYUN.LTD. All rights reserved.
 */
package com.cory.admin.sys.config;

import javax.servlet.http.HttpServletRequest;

import com.cory.admin.sys.core.handle.SystemHandle;
import org.springframework.stereotype.Service;
import com.cory.boot.domain.bean.Principal;
import com.cory.boot.sys.service.SysService;
import com.cory.utils.web.WebUtils;

/**
 * @author xiongcong
 * @date 2022-01-10
 */
@Service
public class AdminService implements SysService {

    @Override
    public Principal getPrincipal() {
        HttpServletRequest request = WebUtils.getRequest();
        if (request != null) {
            return (Principal)request.getSession().getAttribute(AdminConstants.SESSION_USER_INFO);
        }
        return null;
    }

    @Override
    public String getSystem() {
        HttpServletRequest request = WebUtils.getRequest();
        if (request != null) {
            SystemHandle.SystemSession systemSession = (SystemHandle.SystemSession)request.getSession().getAttribute(AdminConstants.SESSION_SYSTEM);
            return systemSession != null ? systemSession.getSystem() : null;
        }
        return null;
    }
}
